package com.example.demo.controller;

import com.example.demo.bean.User;
import com.example.demo.bean.Word;
import com.example.demo.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Jim Chen
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/word")
public class WordController {

    @Autowired
    private WordService wordService;

    @RequestMapping(value="/importData", method = RequestMethod.GET)
    @ResponseBody
    public String importData(HttpServletRequest request){
        return wordService.importData();
    }

    @RequestMapping(value = "/translate", method = RequestMethod.POST)
    @ResponseBody
    public String translate(@RequestBody String word) {
        return wordService.translate(word);
    }

    @RequestMapping(value = "/reverse", method = RequestMethod.POST)
    @ResponseBody
    public String reverse(@RequestBody String word) {
        return wordService.reverse(word);
    }

    @RequestMapping(value="/getAbbr/{englishName}", method = RequestMethod.GET)
    public String findEnglishAbbrByEnglishName(@PathVariable String englishName) {
        return wordService.findEnglishAbbrByEnglishName(englishName);
    }

    @RequestMapping(value="/getAbbrs/{englishName}", method = RequestMethod.GET)
    public List<Word> findEnglishAbbrsByEnglishName(@PathVariable String englishName) {
        return wordService.findEnglishAbbrsByEnglishName(englishName);
    }

    @RequestMapping(value="/getEnglishName/{englishAbbr}", method = RequestMethod.GET)
    public String findEnglishNameByEnglishAbbr(@PathVariable String englishAbbr) {
        return wordService.findEnglishNameByEnglishAbbr(englishAbbr);
    }

    @RequestMapping(value="/getEnglishNames/{englishAbbr}", method = RequestMethod.GET)
    public List<Word> findEnglishNamesByEnglishAbbr(@PathVariable String englishAbbr) {
        return wordService.findEnglishNamesByEnglishAbbr(englishAbbr);
    }

    @RequestMapping(value="/getByChineseName/{ChineseName}", method = RequestMethod.GET)
    public List<Word> findEnglishNameByChineseName(@PathVariable String ChineseName) {
        return wordService.findEnglishNameByChineseName(ChineseName);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public List<Word> list(HttpServletRequest request){
        return wordService.findAll();
    }
}
